package org.come.log;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.ImageObserver;
import java.util.ArrayList;
import java.util.Arrays;

import Main.main;
import com.tool.tcp.Sprite;
import com.tool.tcp.SpriteFactory;
import org.come.login.SpriteBtn;
import org.come.socket.DownLoadTxt;
import org.come.init.ClientCheckUpdate;
import java.io.IOException;
import java.io.Reader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.util.Properties;
import javax.swing.*;
import javax.swing.text.*;

import com.tool.tcpimg.UIUtils;

import java.util.List;
import com.tool.tcpimg.ChatBox;
import org.come.init.CheckUpdate;
import org.come.until.SrcollPanelUI;

public class LanderJPanel extends JPanel
{
    private static JLabel offBtn;
    private static JLabel suoxiao;
    public static JLabel kais;
    private static JLabel jinggao;
    private static JLabel shezhi;
    private static JLabel version;
    private static JLabel version1;
    private static JLabel version2;
    private static JLabel progressBg;
    private static JLabel progress;
    private static JLabel announcement;
    private static JPanel announcement1;
    private static JScrollPane jScrollPane;
    public static JLabel labCheck;
    private LanderJFrame landerJFrame;
    public static CheckUpdate checkUpdate;
    ChatBox box;
    private List<String> sb;
    private int time;
    private String versionx;
    public static String jsonObject;
    public static String ip;
    public static int port;
    public static int width;
    public static int high;
    public JLabel mouse;
    private ImageIcon iconS;
    private static JLabel jindu;
    static Sprite tcp1 = SpriteFactory.VloadSprite("skin/8100226/rg-bt/按钮/按钮.was", null);//特效路径

    public List<ImageIcon>guanggao=new ArrayList<>();
    public TcpBtn tcpBtn;
    MyJpanel k=new MyJpanel();
    SpriteBtn spriteBtn;
    JPanel jPanel;
    public LanderJPanel(final LanderJFrame landerJFrame) {
        box = new ChatBox();
        this.sb = this.getGG();
        this.setLayout(null);
        this.setOpaque(false);

        this.setBackground(UIUtils.Color_BACK);
        this.setPreferredSize(new Dimension(1186, 605));
        (LanderJPanel.suoxiao = new JLabel()).setBounds(963, 100, 35, 35);
        LanderJPanel.suoxiao.setIcon(new ImageIcon("img/0244-FF5102FC (13).png"));
        this.add((Component)LanderJPanel.suoxiao);
        LanderJPanel.suoxiao.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(final MouseEvent e) {
                super.mouseReleased(e);
                LanderJPanel.suoxiao.setIcon(new ImageIcon("img/0244-FF5102FC (13).png"));
                final LanderJFrame val$landerJFrame = landerJFrame;
                LanderJFrame.frame.setExtendedState(1);
            }
        });
        this.rides();
    }

    public void rides() {
        (LanderJPanel.shezhi = new JLabel()).setOpaque(false);
        LanderJPanel.shezhi.setBorder(null);
        LanderJPanel.shezhi.setBackground(UIUtils.Color_BACK);
        LanderJPanel.shezhi.setBounds(1003, 100, 35, 35);
        LanderJPanel.shezhi.setIcon(new ImageIcon("img/0244-FF5102FC (60).png"));
        this.add((Component)LanderJPanel.shezhi);
        LanderJPanel.shezhi.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(final MouseEvent e) {
                LanderJPanel.shezhi.setIcon(new ImageIcon("img/0244-FF5102FC (60).png"));
                new LaddJFrame();
                LaddJFrame.readSysteminit();
                LaddJFrame.readSysteminitlog();
            }
        });
        final Font font = new Font("宋体", 0, 12);
        (LanderJPanel.announcement1 = new JPanel()).setPreferredSize(new Dimension(390, this.sb.size() * 19));
        LanderJPanel.announcement1.setOpaque(false);
        LanderJPanel.announcement1.setLayout(null);
        (LanderJPanel.jScrollPane = new JScrollPane()).setVerticalScrollBarPolicy(22);
        LanderJPanel.jScrollPane.getVerticalScrollBar().setUnitIncrement(10);
        LanderJPanel.jScrollPane.getViewport().setOpaque(false);
        LanderJPanel.jScrollPane.setOpaque(false);
        LanderJPanel.jScrollPane.setBorder(BorderFactory.createEmptyBorder());
        LanderJPanel.jScrollPane.setHorizontalScrollBarPolicy(31);
        LanderJPanel.jScrollPane.setViewportView((Component)LanderJPanel.announcement1);
        LanderJPanel.jScrollPane.setBounds(530,320,400,160);
        LanderJPanel.jScrollPane.getVerticalScrollBar().setUI(null);
        this.box = new ChatBox(0);
        int i = 0;
        while (i < this.sb.size()) {
            this.box.addText((String)this.sb.get(i), 350, font);
            (LanderJPanel.announcement = new JLabel((String)this.sb.get(i))).setBounds(10, 18 * i, 390, 18);
            LanderJPanel.announcement.setBackground(null);
            LanderJPanel.announcement.setForeground(Color.white);
            LanderJPanel.announcement.setFont(font);
            LanderJPanel.announcement.setOpaque(false);
            LanderJPanel.announcement1.add((Component)this.box);
            ++i;
        }
        this.add((Component)LanderJPanel.jScrollPane);
        (LanderJPanel.offBtn = new JLabel()).setBounds(1043, 100, 35, 35);
        LanderJPanel.offBtn.setIcon(new ImageIcon("img/0244-FF5102FC (192).png"));
        LanderJPanel.offBtn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(final MouseEvent e) {
                super.mouseReleased(e);
                LanderJPanel.offBtn.setIcon(new ImageIcon("img/0244-FF5102FC (10).png"));
                System.exit(0);
            }

            @Override
            public void mousePressed(final MouseEvent e) {
                super.mousePressed(e);
            }

            @Override
            public void mouseEntered(final MouseEvent e) {
                super.mouseEntered(e);
                LanderJPanel.offBtn.setIcon(new ImageIcon("img/0244-FF5102FC (30).png"));
            }

            @Override
            public void mouseExited(final MouseEvent e) {
                super.mouseExited(e);
                LanderJPanel.offBtn.setIcon(new ImageIcon("img/0244-FF5102FC (192).png"));
            }
        });
        LanderJPanel.offBtn.setOpaque(false);

        this.add((Component)LanderJPanel.offBtn);
        k.setBounds(530,110,400,300);
        this.add(k);
        jPanel=new JPanel(){

            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                tcp1.updateToTime(System.currentTimeMillis()/2,0);
                tcp1.draw(g,-48,-40);
                if (kais!=null){
                    if (kais.getText().equals("更新完成")){
                        LanderJPanel.kais.setIcon(new ImageIcon("img/sucai/开始按钮3.png"));
                        LanderJPanel.kais.setBounds(15,17,128,56);

                    }else {
                        kais.setBounds(30,35,78,23);
                    }
                }
            }

        };
        jPanel.setOpaque(false);
        jPanel.setBounds(930,400,150,80);


        LanderJPanel.kais = new JLabel();
        kais.setBounds(100,100,78,23);
        // jPanel.addMouseListener(new TcpBtn());
        this.add(jPanel);


        LanderJPanel.kais.setIcon(new ImageIcon("img/sucai/下载按钮.png"));
        kais.setText("下载中");
        LanderJPanel.kais.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(final MouseEvent e) {
                super.mousePressed(e);
                if (kais.getText().equals("更新完成")){
                    LanderJPanel.kais.setIcon(new ImageIcon("img/sucai/开始按钮3.png"));
                    LanderJPanel.kais.setBounds(15,17,128,56);
                }else {


                    LanderJPanel.kais.setIcon(new ImageIcon("img/sucai/下载按钮1.png"));
                    kais.setBounds(30,35,78,23);
                }

            }

            @Override
            public void mouseReleased(final MouseEvent ee) {
                super.mouseReleased(ee);
                if (LanderJPanel.kais.getText().equals("下载中")||LanderJPanel.kais.getText().equals("更新中")) {
                    return;
                }
                else {
                    LanderJPanel.kais.setIcon(new ImageIcon("img/sucai/开始按钮3.png"));
                    LanderJPanel.kais.setBounds(15,17,128,56);
                    final Properties properties = new Properties();
                    FileInputStream fis = null;
                    InputStreamReader isr = null;
                    try {
                        fis = new FileInputStream("resource/other/lander.txt");
                        isr = new InputStreamReader((InputStream)fis, "UTF-8");
                        properties.load((Reader)isr);
                        if ("2".equals(properties.getProperty("ctbox"))) {
                            LanderJPanel.width = 800;
                            LanderJPanel.high = 600;
                        }
                        else {
                            LanderJPanel.width = 640;
                            LanderJPanel.high = 480;
                        }
                        if ("2".equals(properties.getProperty("Label"))) {
                            LanderJFrame.frame.setVisible(false);
                            // tab.Main.main(new String[0]);
                            //如果出包用单开，就吧这个注释取消
                            com.tool.tab.Main.main(new String[0]);
//                            com.mains.Main.main(new String[0]);//如果出包用多开，就吧这个注释取消
                            if ("1".equals(properties.getProperty("music"))) {
                                //  org.come.qianqiu.Main.yinxiao(false);
                            }
                        }
                        else {
                            LanderJFrame.frame.setVisible(false);
                            //  org.come.qianqiu.Main.yinxiao(false);
                            try {
                                com.main.Main.main(new String[0]);
                            }
                            catch (Exception ex) {
                                ex.printStackTrace();
                            }
                        }
                    }
                    catch (Exception exception) {
                        exception.printStackTrace();
                        try {
                            if (isr != null) {
                                isr.close();
                            }
                        }
                        catch (IOException e) {
                            e.printStackTrace();
                        }
                        try {
                            if (fis != null) {
                                fis.close();
                            }
                        }
                        catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    finally {
                        try {
                            if (isr != null) {
                                isr.close();
                            }
                        }
                        catch (IOException e2) {
                            e2.printStackTrace();
                        }
                        try {
                            if (fis != null) {
                                fis.close();
                            }
                        }
                        catch (IOException e2) {
                            e2.printStackTrace();
                        }
                    }
                    return;
                }
            }

            @Override
            public void mouseEntered(final MouseEvent e) {
                super.mouseEntered(e);
                if ( LanderJPanel.kais.getText().equals("更新完成")){
                    LanderJPanel.kais.setIcon(new ImageIcon("img/sucai/开始游戏-点击.png"));
                    LanderJPanel.kais.setBounds(16,19, 128, 56);
                }else {


                    LanderJPanel.kais.setIcon(new ImageIcon("img/sucai/下载按钮1.png"));
                    kais.setBounds(30,35,78,23);
                }

            }

            @Override
            public void mouseExited(final MouseEvent e) {
                super.mouseExited(e);
                if ( LanderJPanel.kais.getText().equals("更新完成")){

                    LanderJPanel.kais.setIcon(new ImageIcon("img/sucai/开始按钮3.png"));
                    LanderJPanel.kais.setBounds(15,17,128,56);
                }else {
                    LanderJPanel.kais.setIcon(new ImageIcon("img/sucai/下载按钮.png"));
                    kais.setBounds(30,35,78,23);
                }

            }
        });
        // this.add((Component)LanderJPanel.kais);
        jPanel.add((Component)LanderJPanel.kais);
        (LanderJPanel.jinggao = new JLabel()).setIcon(new ImageIcon("img/0244-FF5102FC (15).png"));
        LanderJPanel.jinggao.setBounds(1138, 320, 48, 62);
        this.add((Component)LanderJPanel.jinggao);
        //  (LanderJPanel.version1 = new JLabel()).setText("当前版本：" + ClientCheckUpdate.getVersion());
        (LanderJPanel.version1 = new JLabel()).setText("正在检查更新...");
        LanderJPanel.version1.setFont(new Font("楷体", 0, 13));
        LanderJPanel.version1.setBounds(950, 480, 112, 15);
        version1.setVisible(true);
        this.add((Component)LanderJPanel.version1);
        (LanderJPanel.version2 = new JLabel()).setText("正在检查更新...");
        LanderJPanel.version2.setFont(new Font("楷体", 0, 13));
        LanderJPanel.version2.setBounds(950, 500, 250, 15);
        version2.setVisible(true);
        this.add((Component)LanderJPanel.version2);
        (LanderJPanel.version = new JLabel()).setFont(new Font("楷体", 0, 13));
        LanderJPanel.version.setBounds(1028, 430, 112, 15);
        this.add((Component)LanderJPanel.version);
        (LanderJPanel.progressBg = new JLabel(new ImageIcon("img/0244-FF5102FC (89).png"))).setBounds(200, 410, 972, 74);
        LanderJPanel.progressBg.setVisible(false);
        this.add((Component)LanderJPanel.progressBg);
        (LanderJPanel.progress = new JLabel(new ImageIcon("img/0244-FF5102FC (109).png"))).setOpaque(false);
        LanderJPanel.progress.setVisible(false);
        this.add((Component)LanderJPanel.progress);
        Timer timer = new Timer(50, new ActionListener() { // 每1000毫秒触发一次
            @Override
            public void actionPerformed(ActionEvent e) {
                counter++;
                repaint(); // 重新绘制
            }
        });
        timer.start();


    }
    private int counter = 0;
    public List<String> getGG() {
        final String v = DownLoadTxt.GetServerTxtGG("gg.txt");
        if (v != null && v.length() != 0) {
            String[] vs = v.split("\r\n");
            if (vs.length == 1) {
                vs = v.split("\n");
            }
            return Arrays.asList(vs);
        }
        else {
            return new ArrayList();
        }
    }
    static Sprite tcp = SpriteFactory.VloadSprite("skin/8100226/rg-bt/云下方.was", null);//特效路径
    static Sprite tcp2 = SpriteFactory.VloadSprite("skin/8100226/rg-bt/飘云左.was", null);//特效路径
    static Sprite tcp3 = SpriteFactory.VloadSprite("skin/8100226/rg-bt/麦穗1.was", null);//特效路径
    static Sprite tcp4 = SpriteFactory.VloadSprite("skin/8100226/rg-bt/金色云左.was", null);//特效路径
    ImageIcon zhutu=new ImageIcon("img/sucai/主图2.png");
    ImageIcon zhutu1=new ImageIcon("img/sucai/山头.png");
    ImageIcon zhutu2=new ImageIcon("img/sucai/经典版1.png");
    @Override
    protected void paintComponent(final Graphics g) {
        super.paintComponent(g);
        if (this.iconS == null) {
            this.iconS = new ImageIcon("img/sucai/0204-f30f35f9-0.png");
        }
        g.drawImage(this.iconS.getImage(), 0, 0, 1186, 605, (ImageObserver)this);
        g.drawImage(zhutu.getImage(),50,0,580,550,null);
        g.drawImage(zhutu1.getImage(),990,303,118,141,null);
        g.drawImage(zhutu2.getImage(),1017,316,64,80,null);
        final ImageIcon icon = new ImageIcon("img/0093-63693E4D.png");
        g.drawImage(icon.getImage(), 141, -5, 535, 515, (ImageObserver)this);
        final ImageIcon icon2 = new ImageIcon("img/0244-FF5102FC (110).png");
        g.drawImage(icon2.getImage(), 280, 450, 763, 49, (ImageObserver)this);
        tcp.updateToTime(System.currentTimeMillis(),0);
        tcp.draw(g,100,400);
        tcp3.updateToTime(System.currentTimeMillis()/2,0);
        tcp3.draw(g,900,190);
        tcp2.updateToTime(System.currentTimeMillis()/4,0);
        tcp2.draw(g,320,56);
        tcp4.updateToTime(System.currentTimeMillis()/2,0);
        tcp4.draw(g,100,400);

    }

    public JLabel getOffBtn() {
        return LanderJPanel.offBtn;
    }

    public void setOffBtn(final JLabel offBtn) {
        LanderJPanel.offBtn = offBtn;
    }

    public JLabel getSuoxiao() {
        return LanderJPanel.suoxiao;
    }

    public void setSuoxiao(final JLabel suoxiao) {
        LanderJPanel.suoxiao = suoxiao;
    }

    public static JLabel getKais() {
        return LanderJPanel.kais;
    }

    public static void setKais(final JLabel kais) {
        LanderJPanel.kais = kais;
    }

    public static JScrollPane getjScrollPane() {
        return LanderJPanel.jScrollPane;
    }

    public static void setjScrollPane(final JScrollPane jScrollPane) {
        LanderJPanel.jScrollPane = jScrollPane;
    }

    public LanderJFrame getLanderJFrame() {
        return this.landerJFrame;
    }

    public void setLanderJFrame(final LanderJFrame landerJFrame) {
        this.landerJFrame = landerJFrame;
    }

    public ImageIcon getIconS() {
        return this.iconS;
    }

    public void setIconS(final ImageIcon iconS) {
        this.iconS = iconS;
    }

    public JLabel getJinggao() {
        return LanderJPanel.jinggao;
    }

    public void setJinggao(final JLabel jinggao) {
        LanderJPanel.jinggao = jinggao;
    }

    public JLabel getShezhi() {
        return LanderJPanel.shezhi;
    }

    public void setShezhi(final JLabel shezhi) {
        LanderJPanel.shezhi = shezhi;
    }

    public static JLabel getVersion() {
        return LanderJPanel.version;
    }

    public static void setVersion(final JLabel version) {
        LanderJPanel.version = version;
    }

    public static JLabel getVersion1() {
        return LanderJPanel.version1;
    }

    public static void setVersion1(final JLabel version1) {
        LanderJPanel.version1 = version1;
    }

    public static CheckUpdate getCheckUpdate() {
        return LanderJPanel.checkUpdate;
    }

    public static void setCheckUpdate(final CheckUpdate checkUpdate) {
        LanderJPanel.checkUpdate = checkUpdate;
    }

    public ChatBox getBox() {
        return this.box;
    }

    public void setBox(final ChatBox box) {
        this.box = box;
    }

    public List<String> getSb() {
        return this.sb;
    }

    public void setSb(final List<String> sb) {
        this.sb = sb;
    }

    public int getTime() {
        return this.time;
    }

    public void setTime(final int time) {
        this.time = time;
    }

    public String getVersionx() {
        return this.versionx;
    }

    public void setVersionx(final String versionx) {
        this.versionx = versionx;
    }

    public static JLabel getProgressBg() {
        return LanderJPanel.progressBg;
    }

    public static void setProgressBg(final JLabel progressBg) {
        LanderJPanel.progressBg = progressBg;
    }

    public static JLabel getProgress() {
        return LanderJPanel.progress;
    }

    public static void setProgress(final JLabel progress) {
        LanderJPanel.progress = progress;
    }

    public static JLabel getAnnouncement() {
        return LanderJPanel.announcement;
    }

    public static void setAnnouncement(final JLabel announcement) {
        LanderJPanel.announcement = announcement;
    }

    public static JPanel getAnnouncement1() {
        return LanderJPanel.announcement1;
    }

    public static void setAnnouncement1(final JPanel announcement1) {
        LanderJPanel.announcement1 = announcement1;
    }

    public static JLabel getLabCheck() {
        return LanderJPanel.labCheck;
    }

    public static void setLabCheck(final JLabel labCheck) {
        LanderJPanel.labCheck = labCheck;
    }

    public static String getJsonObject() {
        return LanderJPanel.jsonObject;
    }

    public static void setJsonObject(final String jsonObject) {
        LanderJPanel.jsonObject = jsonObject;
    }

    public static String getIp() {
        return LanderJPanel.ip;
    }

    public static void setIp(final String ip) {
        LanderJPanel.ip = ip;
    }

    public static int getPort() {
        return LanderJPanel.port;
    }

    public static void setPort(final int port) {
        LanderJPanel.port = port;
    }

    public static JLabel getVersion2() {
        return version2;
    }

    public static void setVersion2(JLabel version2) {
        LanderJPanel.version2 = version2;
    }
    public class MyJpanel extends JPanel{
        int i=1;
        ImageIcon icon;
        ImageIcon icon1=new ImageIcon("img/area/公告栏.png");

        public  MyJpanel(){
            this.setPreferredSize(new Dimension(402, 500));
            this.setLayout(null);
            this.setOpaque(false);
            for (int i=0;i<=6;i++){
                if (i==0){
                    ImageIcon icon=new ImageIcon("img/area/"+i+".png");
                    guanggao.add(icon);
                }else {
                    ImageIcon icon=new ImageIcon("img/area/t"+i+".png");
                    guanggao.add(icon);
                }
                icon=guanggao.get(i);
            }
            Timer timer=new Timer(2000, new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    i++;
                    if (i>=7)
                        i=1;
                }
            });
            timer.start();


        }
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(guanggao.get(i).getImage(),0,0,400,184,null);
            g.drawImage(icon1.getImage(),0,185,400,168,null);
        }


    }
}
